<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class User extends BaseModel
{

    protected $table = 'user';

    /**
     * 表明模型是否应该被打上时间戳
     *
     * @var bool
     */
    public $timestamps = true;

    protected $fillable = [
        'user_name',
        'user_type',
        'user_tel',
        'reg_date',
        'cd_num',
        'yu_e',
        'card_yu_e',
        'head_img',
        'county',
        'created_by',
        'created_at'
    ];


    /**
     * 用户列表
     */
    public static function GetUserList($pageSize, $page, $map, $sort)
    {
        return self::select('*')->where($map)
            ->orderBy($sort)
            ->paginate($pageSize, [], 'page', $page)->toArray();
    }


    /**
     * user reg
     *
     * @return void
     */
    public static function UserReg($data)
    {
        try {
            $user_tel = $data['user_tel'];
            if (!empty($user_tel)) {
                $res = self::where('user_tel', $user_tel)->first();
                if (!$res) {
                    $res = self::create($data);
                }
                return $res;
            }
        } catch (\Exception $e) {
            return self::result('', 500, $e->getMessage());
        }
    }
}
